package pers.w.chaptertalk.reader;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import java.util.Objects;

import pers.w.chaptertalk.MyService;


public class PlayerReceiver extends BroadcastReceiver {

    private static final String TAG = "player receiver";
    // private static ReaderActivity reader;
    // private static String last_action = "";

//    public void setSpoken(ReaderActivity reader) {
//        PlayerReceiver.reader = reader;
//    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive: " + intent.getAction());
        String action = intent.getAction();
        // if (!last_action.equals(action)) {
        if (context instanceof ReaderActivity) {
            ReaderActivity reader = (ReaderActivity) context;
            switch (Objects.requireNonNull(action)) {
                case MyService.ACTION_PAUSE:
                    reader.spoken_setting.pause();
                    break;
                case MyService.ACTION_STOP:
                    reader.spoken_setting.stopSpoken(false);
                    break;
                case MyService.ACTION_RESUME:
                    reader.spoken_setting.resume();
                    break;
                case MyService.ACTION_SHOW_READER:
                    reader.show();
                    break;
            }
            //last_action = action;
        }
    }
}
